import Store from "@/store";

export default {
  install: function (Vue) {
    // auth
    Vue.prototype.hasAuth = (data) => {
      return Store.getters.hasAuth(data);
    };

    Vue.directive("auth", {
      inserted(el, binding) {
        var value = binding.value;
        let hasAuth = Store.getters.hasAuth(value);
        if (!hasAuth) {
          el.parentNode.removeChild(el);
        }
      },
    });

    Vue.directive("resize", {
      bind(el, binding) {
        // el为绑定的元素，binding为绑定给指令的对象
        let width = "",
          height = "";
        function isReize() {
          const style = document.defaultView.getComputedStyle(el);
          if (width !== style.width || height !== style.height) {
            binding.value(); // 关键
          }
          width = style.width;
          height = style.height;
        }
        el.__vueSetInterval__ = setInterval(isReize, 300);
      },
      unbind(el) {
        clearInterval(el.__vueSetInterval__);
      },
    });
  },
};
